{{include file="header.html"}}
	<div class="header new_header	">
		<div class="nav">
			<div class="search"><a href="javascript:history.go(-1);"></a></div>
		    <div class="title"><a href="javascript:">商品列表</a></div>
		    <div class="right listicon">
		        <a href="javascript:" class="row_icon" {{if $mode == 'row'}}style="display:none;"{{/if}}><img src="{{$smarty.const.__APP__}}images/row.png" alt=""></a>
		        <a href="javascript:" class="cos_icon" {{if $mode == 'cos'}}style="display:none;"{{/if}}><img src="{{$smarty.const.__APP__}}images/cos.png" alt=""></a>
		    </div>
		</div>
	</div>
	<div class="container">
		<div class="goods">
			<div class="goodslist {{if $mode == 'cos'}}cos{{/if}}">
				<div id="wrapper" style="height:100%;">
					<div id="scroller">
						<ul>
							<li {{if !$smarty.get.type}}class="current"{{/if}}>
								<a href="index.php?app=Goods{{if $smarty.get.sort}}&sort={{$smarty.get.sort}}{{/if}}{{if $smarty.get.order}}&order={{$smarty.get.order}}{{/if}}{{if $smarty.get.keyword}}&keyword={{$smarty.get.keyword}}{{/if}}">
									<img class="baseimg" src="{{$smarty.const.__APP__}}images/list1.png" alt="">
									<img class="onimg" src="{{$smarty.const.__APP__}}images/list1on.png" alt="">
									全部
								</a>
							</li>
						{{if $result.type}}
						{{foreach from=$result.type item=val key=key}}
							<li {{if $smarty.get.type == $key}} class="current" {{/if}}>
								<a href="index.php?app=Goods&type={{$key}}{{if $smarty.get.sort}}&sort={{$smarty.get.sort}}{{/if}}{{if $smarty.get.order}}&order={{$smarty.get.order}}{{/if}}{{if $smarty.get.keyword}}&keyword={{$smarty.get.keyword}}{{/if}}">
									<img class="baseimg" src="{{$smarty.const.__APP__}}images/list16.png" alt="">
									<img class="onimg" src="{{$smarty.const.__APP__}}images/list16on.png" alt="">
									{{$val.title}}
								</a>
							</li>
						{{/foreach}}
						{{/if}}
						</ul>
					</div>
					<script src="{{$smarty.const.__APP__}}js/iscroll.js" type="text/javascript"></script>
					<script type="text/javascript">
						$(function(){

							//获得列表的高度
							function tabheight(){
								var all_height=0;
								$('.goodslist li').each(function(){
									var height = $(this).height()+1;
									all_height =all_height+height;
								})
								$('#scroller').css('height',all_height+$('.nav').height()+$('.footer').height());
							}
							
							//滚动		
							var myScroll;
							function loaded() {
								tabheight();
								$('.goodslist').css('position','fixed');
								myScroll = new iScroll('wrapper',{
									vScrollbar:false,
									hScrollbar:false,
									bounce:false,
									bounceLock:false,
									checkDOMChanges:true,
								});
							}
							loaded();

							//当前菜单始终显示在屏幕内
							var offsettop  = $('.goodslist li.current').offset().top+$('.goodslist li.current').innerHeight();
							var windowHeight = $(window).height()-$('.footer').height();
							if(offsettop>windowHeight){
								var scrolltop = -(offsettop - windowHeight);
								$('#scroller').css('transform','matrix(1,0,0,1,0,'+scrolltop+')');
							}

							//模式切换
							$('.listicon').click(function(){
								$('.row_icon').toggle();
								$('.cos_icon').toggle();
								$('.goodslist').toggleClass('cos');
								$('.goodsbox').toggleClass('rows');
								if($('.goodslist').hasClass('cos'))
									$.cookie('mode', 'cos', {expires: 30,path: "/"});
								else
									$.cookie('mode', 'row', {expires: 30,path: "/"});
								loaded();  //重新调用loade()函数
								myScroll.refresh();
							});
							
							//定位
							function tab_pos(){
								var window_width=$(window).width();
								if(window_width>720){
									$('.goodslist').css({"left":"50%","margin-left":"-360px"})
								}else{
									$('.goodslist').css({"left":"0","margin-left":"0"})
								}
							}
							tab_pos();
							$(window).resize(function(){
								tab_pos();
							})
							
						});	
				
					</script>
				</div>
			</div>
			<div class="goodsbox  {{if $mode == 'row'}}rows{{/if}}">
				<div class="goods_item">
					<ul>
						<li {{if !$smarty.get.sort or $smarty.get.sort == 'rate'}}class="current"{{/if}} id="rate" onClick="sort('rate')"><a href="javascript:">购买量</a></li>
						<li {{if $smarty.get.sort == 'hit'}}class="current"{{/if}} id="hit" onClick="sort('hit')"><a href="javascript:">人气</a></li>
						<li {{if $smarty.get.sort == 'adddate'}}class="current"{{/if}} id="adddate" onClick="sort('adddate')" ><a href="javascript:">最新</a></li>
						<li {{if $smarty.get.sort == 'price'}}class="current {{if $smarty.get.order=='asc'}}asc{{/if}}"{{/if}} id="price" onClick="sort('price')"><a href="javascript:">价值<i></i></a></li>
					</ul>
					<div class="clear"></div>
				</div>
				
				<ul class="i_ul">
					
				</ul>
				<div class="win_empty" style="display:none">
					<i></i>
				</div>
			</div>
		</div>
	</div>
<script type="text/javascript">
	//排序
	function sort(type){
		var obj = $('#'+type);
		var url = "{{$smarty.server.REQUEST_URI}}";
		var order = 'desc';
		if($(obj).hasClass("current") && !$(obj).hasClass("asc")){
			order = 'asc';
		}
		url = setURLArg(setURLArg(url,'sort',type),'order',order);
		document.location.href = url;
	}
</script>
<script type="text/javascript">

	var page = 1;
	var over = false;
	if(!over)
		loadmore();
	function loadmore(){
		if(over == true) return false;
		$.get('{{"index.php?app=Goods&act=getList"|URL}}',{page:page,sort:'{{$smarty.get.sort}}',type:'{{$smarty.get.type}}',order:'{{$smarty.get.order}}',keyword:'{{$smarty.get.keyword}}'},function(xml){
		if(xml.statusCode == '200'){
			$(".i_ul").append(xml.message);	
			page++;
			shop_cart();
		}else{
			over = true;
			$('.win_empty').show();
			}
 		},'json');  
	}

	$(document).ready(function(){
		$(window).scroll(function(){
			var scrollTop = $(this).scrollTop();               //滚动条距离顶部的高度
	  　　	var scrollHeight = $(document).height();           //当前页面的总高度
	  　　	var windowHeight = $(this).height();               //当前可视的页面高度
	  　		if(scrollTop + windowHeight >= scrollHeight){        //距离顶部+当前高度 >=文档总高度 即代表滑动到底部
	  			if(!over) loadmore();
	        }
	   });
	});
</script>
{{include file="footer2.html"}}